#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject 
@File    : order_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/4/26 15:53 
@Describe: 订单相关接口
"""
from APIs.posApi.base_pos_api import BasePosApi
from Comm.tools.toolsControl import ToolsHandler


class OrderApi(BasePosApi):

    def __init__(self, brandCode, environment):
        super().__init__(brandCode, environment)

    def order_submit(self, json_data):
        """
        提交堂食订单
        :param json_data: 下单数据
        :return:
        """
        payload = json_data
        response = self.http_requests('order/submit', payload)
        return response

    def order_detail(self, orderNo):
        """
        台位订单详情
        :param orderNo:订单号
        :return:
        """
        payload = '{"orderNo":"' + orderNo + '"}'
        response = self.http_requests('order/detail', payload)
        return response

    def get_vip_info(self, cardNo):
        """
        获取会员详细信息
        :param cardNo: 会员号
        :return:
        """
        payload = '{"cardNo":"' + cardNo + '"}'
        response = self.http_requests('order/vip/input', payload)
        return response

    def vip_bind(self, cardNo, orderNo):
        """
        订单绑定会员
        :param cardNo: 会员号
        :param orderNo: 订单号
        :return:
        """
        vip_info = self.get_vip_info(cardNo)
        customerId = ToolsHandler.get_json_result(vip_info, '$..customerId')
        payload = '{"cardNo":"' + cardNo + '","customerId":"' + str(customerId) + '","orderNo":"' + orderNo + '"}'
        response = self.http_requests('order/vip/bind', payload)
        return response

    def order_summary_list(self, startTime, endTime, pageNum='1', pageSize='100', businessType='1', orderStatus='1'):
        """
        订单列表查询
        :param startTime: 开始时间
        :param endTime: 结束时间
        :param pageNum: 第几页，默认1
        :param pageSize: 每页展示几条，默认100
        :param businessType: 订单类型 1:堂食 2:外卖
        :param orderStatus: 0:未结、1:已结、2:未退、3:已退
        :return:
        """
        payload = '{"endTime":"' + endTime + '","startTime":"' + startTime + '","businessType":"' + businessType + '","pageNum":"' + pageNum + '","pageSize":"' + pageSize + '","orderStatus":"' + orderStatus + '"}'
        response = self.http_requests('order/summary/list', payload)
        return response

    def order_summary_canteen_detail(self, orderNo, customerId: str):
        """
        堂食正向订单详情
        :param orderNo:	订单号
        :param customerId: 会员id
        :return:
        """
        payload = '{"orderNo":"' + orderNo + '","customerId":"' + customerId + '"}'
        response = self.http_requests('order/summary/canteen/detail', payload)
        return response

    def order_summary_canteen_refund_detail(self, orderNo, customerId='1000350379'):
        """
        堂食逆向订单详情
        :param orderNo: 订单号
        :param customerId: 会员id
        :return:
        """
        payload = '{"orderNo":"' + orderNo + '","customerId":"' + customerId + '"}'
        response = self.http_requests('order/summary/canteen/refund-detail', payload)
        return response

    def pos_work_detail(self, startDate, endDate, work_type='3', businessType='1'):
        """
        员工交班记录详情
        :param startDate: 开始时间
        :param endDate: 结束时间
        :param work_type: 类型: 1、单班次交班表 2、POS机号汇总表 3、日汇总 4、门店销售汇总表
        :param businessType: 业务类型： 1、堂食,2、外卖, 不传查询全部
        :return:
        """
        payload = '{"startDate":"' + startDate + '","endDate":"' + endDate + '","type":"' + work_type + '","businessType":"' + businessType + '"}'
        response = self.http_requests('pos/work/detail', payload)
        return response


if __name__ == '__main__':
    from Comm.tools.toolsControl import ToolsHandler

    test = OrderApi('823882', 'sit')
    order_detail = test.pos_work_detail('2022-09-27 00:00:00', '2022-09-27 23:59:59')

